﻿<h1>Concurrency Synchronization Overview</h1>

<p>
This article will explain what are synchronizations
and list the synchronization techniques supported by Go.
</p>

<h3>What Are Concurrency Synchronizations?</h3>

<div>

Concurrency synchronizations means how to control concurrent computations (a.k.a., goroutines in Go)
<ul>
<li>
	to avoid data races between them,
</li>
<li>
	to avoid them consuming CPU resources when they have nothing to do.
</li>
</ul>

<!--
<p>
Often, at run time, in a concurrent program,
a value will be used by multiple goroutines.
For such circumstances, we must control which goroutines
can acquire the ownership of the value at a given time.
Otherwise, data races may happen and the integrity of the value will not get guaranteed.
</p>

<p>
We use all kinds of data synchronization techniques to transfer or guard
value ownership between goroutines to avoid data races in current programs.
</p>

Here, more specifically, about the ownership of a value,
<ul>
<li>
	the write ownership of a value is exclusive.
	In the period of a goroutine owns the write right of a value,
	no other goroutines should use the value, either read or write.
</li>
<li>
	the read ownership of a value is non-exclusive.
	In the period of a goroutine owns the read right of a value,
	other goroutines can also safely read the value,
	but no goroutines should write the value.
</li>
</ul>

<p>
is called concurrency synchronization.
</p>

<p><i>
(In fact, more precisely, to avoid data races,
what we care about is the ownership of some memmory segments.
At run time, a value may occupy multiple memmory segments.
We might not care about the ownership of all the memmory segments
occupied by a value in writing a piece of concurrent code.
But, for explanation simplicity, we will still use
the "ownership of values" wording in descriptions throughout Go 101 articles.)
</i></p>
-->

</div>

<h3>What Synchronization Techniques Does Go Support?</h3>

<div>
The article <a href="channel.html">channels in Go</a>
has shown that we can use channels to do synchronizations.
Besides using channels, Go also supports several other common synchronization techniques,
such as mutex and atomic operations.
Please read the following articles to get how to do synchronizations
with all kinds of techniques in Go:
<ul>
<li><a href="channel-use-cases.html">Channel Use Cases</a></li>
<li><a href="channel-closing.html">How To Gracefully Close Channels</a></li>
<li><a href="concurrent-synchronization-more.html">Concurrency Synchronization Techniques Provided In The <code>sync</code> Standard Package</a></li>
<li><a href="concurrent-atomic-operation.html">Atomic Operations Provided In The <code>sync/atomic</code> Standard Package</a></li>
</ul>
</div>

<p>
We can also do synchronizations by making use of network and file IO.
But such techniques are very inefficient within a single program process.
Generally, they are used for inter-process and distributed synchronizations.
Go 101 will not cover such techniques.
</p>

<p>
To understand these synchronization techniques better,
it is recommended to know the <a href="memory-model.html">memory order guarantees in Go</a>.
</p>

<p>
The data synchronization techniques in Go will not prevent programmers from writing
<a href="concurrent-common-mistakes.html">improper concurrent code</a>.
However these techniques can help programmers write correct concurrent code easily.
And the unique channel related features make concurrent programming flexible and enjoyable.
</p>

